// src/apis/uploadApi.js

/**
 * 上传图片接口
 * @param {File} file - 要上传的文件
 * @returns {Promise} - 返回上传结果的 Promise
 */// src/apis/uploadApi.js
import apiClient from '@/api/axios.js';

export class UploadApi {
    /**
     * 上传图片接口
     * @param {File} file - 要上传的文件
     * @returns {Promise} - 返回上传结果的 Promise
     */
    static async uploadImage(file) {
        try {
            const formData = new FormData();
            formData.append('file', file);

            const response = await apiClient.post('/user_upload', formData, {
                headers: {
                    'Content-Type': 'multipart/form-data'
                }
            });
            console.log('成功请求上传图片',response)
            return response;
        } catch (error) {
            throw new Error(error.message);
        }
    }

    //视频上传
    static async uploadVedio(file) {
        try {
            const formData = new FormData();
            formData.append('video_file', file);

            const response = await apiClient.post('/video_upload', formData, {
                headers: {
                    'Content-Type': 'multipart/form-data'
                }
            });
            console.log('成功请求视频上传',response)
            return response;
        } catch (error) {
            throw new Error(error.message);
        }
    }

    // 视频封面上传
    static async uploadVedioCover(file) {
        try {
            const formData = new FormData();
            formData.append('cover', file);

            const response = await apiClient.post('/cover_upload', formData, {
                headers: {
                    'Content-Type': 'multipart/form-data'
                }
            });
            console.log('成功请求视频上传',response)
            return response;
        } catch (error) {
            throw new Error(error.message);
        }
    }

    // 视频投稿
    static async contributeVideo(params){
        try {
            const response = await apiClient.post('/video/create', params);
            return response;
        } catch (e) {
            console.error('视频投稿错误 ',e);
            return e;
        }
    }

}

